package com.fx.util;

public class StringUtil {

    /**
     * 将sql语句和参数转换为缓存key
     * @param sql
     * @param args
     * @return
     */
    public static String sqlConvertKey(String sql,Object... args){
        if (args == null || args.length ==0){
            return sql.replace("?","&").substring(sql.indexOf("from")+4).replace(" ","");
        }else{
            sql = sql.replace("?","&");
            for (int i = 0; i <args.length ; i++) {
                sql = sql.replaceFirst("&",args[i]+"");
            }
            return sql.substring(sql.indexOf("from")+4).replace(" ","");
        }
    }
}
